package com.huike.web.controller.report;

import com.github.pagehelper.PageHelper;
import com.huike.clues.domain.TbActivity;
import com.huike.clues.domain.TbClue;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import com.huike.contract.domain.TbContract;
import com.huike.report.domain.vo.ActivityStatisticsVo;
import com.huike.report.domain.vo.LineChartVO;
import com.huike.report.domain.vo.VulnerabilityMapVo;
import com.huike.report.service.IReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/report")
public class ReportController extends BaseController {

    @Autowired
    private IReportService reportService;

    /**
     * 漏斗图数据
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/getVulnerabilityMap/{beginCreateTime}/{endCreateTime}")
    public AjaxResult getVulnerabilityMap(@PathVariable String beginCreateTime, @PathVariable String endCreateTime){
        VulnerabilityMapVo vulnerabilityMapDTO= reportService.getVulnerabilityMap(beginCreateTime,endCreateTime);
        return AjaxResult.success(vulnerabilityMapDTO);
    }

    @GetMapping("/chanelStatistics/{beginCreateTime}/{endCreateTime}")
    public List<Map<String,Object>> chanelStatistics(@PathVariable String beginCreateTime, @PathVariable String endCreateTime){
        List<Map<String, Object>> list = reportService.chanelStatistics(beginCreateTime, endCreateTime);
        return list;
    }
    @GetMapping("/activityStatistics/{beginCreateTime}/{endCreateTime}")
    public List<Map<String,Object>> activityStatistics(@PathVariable String beginCreateTime, @PathVariable String endCreateTime){
        List<Map<String, Object>> list = reportService.activityStatistics(beginCreateTime, endCreateTime);
        return list;
    }

    @GetMapping("activityStatisticsList")
    public TableDataInfo activityStatisticsList(TbActivity activity,String beginCreateTime,String endCreateTime){
        List<ActivityStatisticsVo> list= reportService.activityStatisticsList(activity,beginCreateTime,endCreateTime);
        return getDataTablePage(list);
    }

    /**
     * 客户统计
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/contractStatistics/{beginCreateTime}/{endCreateTime}")
    public LineChartVO contractStatistics(@PathVariable String beginCreateTime, @PathVariable String endCreateTime){
        return reportService.contractStatistics(beginCreateTime,endCreateTime);

    }

    @GetMapping("/contractStatisticsList")
    public TableDataInfo cluesStatisticsList( Date beginCreateTime, Date endCreateTime, String channel, String createBy){

        startPage();
      List<TbContract> tbContracts = reportService.cluesStatisticsList(beginCreateTime,endCreateTime,channel,createBy);

        return getDataTable(tbContracts);
    }
}
